$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/terminal/list',
        datatype: "json",
        colModel: [
            { label: '通知id', name: 'terminalId',  width: 60,align:"center", key: true },
            { label: 'SN', name: 'sn',align:"center", width: 120 },
            { label: '终端号', name: 'merchantCode',align:"center", width: 60},
            { label: '类型', name: 'terminalName',align:"center", width: 60 },
            { label: '是否线上', name: 'isOnline',align:"center", width: 60,formatter:function (value,options,row) {
                    return value==1?'线上':"线下";
                }  },
            { label: '是否激活', name: 'isActivation',align:"center", width: 60 ,formatter:function (value,options,row) {
                    return value==2?'已激活':"未激活";
                } },
            { label: '激活时间', name: 'activationDate',align:"center", width: 60,formatter:function (value,options,row) {
                    return value==null?'未激活':value;
                } },
            { label: '二级用户', name: 'username', align:"center", width: 85,formatter:function (value,options,row) {
                    return value==null?'未分配':value;
                } }
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect:true,
        multiboxonly:true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
    vm.BindType();
});




var vm = new Vue({
    el:'#rrapp',
    data:{
        q: {
            startSn: null,
            endSn: null,
            merchantCode: null,
            terminalType: 0
        },
        showList: true,
        title: null,

        terminalTypes: [],


    },
    methods: {
        query: function () {
            vm.reload();
        },
        clean:function(){
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('setGridParam',{'page':1});
            vm.reload();
        },

        reload: function () {

            vm.showList = true;
            vm.showAdd=false;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData: {'startSn': vm.q.startSn,'endSn': vm.q.endSn,'merchantCode':vm.q.merchantCode,'termianlType':vm.q.termianlType},
                page:page
            }).trigger("reloadGrid");
        },
        insert:function () {
            vm.showList=false;
            vm.showAdd=true;
            vm.title="添加消息"
        },
        BindType:function () {
            $.get(baseURL+"sys/terminal/sysTerTypeList",r=>{
                vm.$set(vm.terminalTypes, 0, {
                    terminalType: 0,
                    terminalName: "请选择类型"
                });
                for (var i = 0; i < r.list.length; i++) {
                    vm.$set(vm.terminalTypes, (i + 1), r.list[i]);
                }


            })
        }

    }
});

